{extend name="layout"/}
{block name="css"}
<style>
    .configImage{min-height:100px; padding-bottom: 20px; }
    .dz-default.dz-message{
        right: auto;
        left: 50%;
        top: 25px;
        transform: none;
        padding-left: 0;
        font-size: 35px;
        font-weight: 400;
        line-height: 35px;
        position: relative
    }
</style>
{/block}
{block name="content"}
<div class="alert alert-default">
    <button type="button" class="close" data-dismiss="alert">×</button>
    创建时间：{$info['create_time']}&nbsp;&nbsp;&nbsp;上次登录时间：{$info['last_login_time']}&nbsp;&nbsp;&nbsp;&nbsp;上次登录IP：{$info['last_login_ip']}
</div>
<div class="panel">
    <div class="panel-heading">
        <div class="panel-title">{$info['username']} [{$gname}]</div>
    </div>
    <form enctype="multipart/form-data" class="panel-body" method="post" action="">
        {if $ifAcc}
        <fieldset class="form-group">
            <label>账户*</label>
            <input type="text" class="form-control" name="username" placeholder="登录账户" value="{$info['username']}">
        </fieldset>
        {/if}
        <fieldset class="form-group">
            <label>姓名*</label>
            <input type="text" class="form-control" name="realname" placeholder="真实姓名" value="{$info['realname']}">
        </fieldset>
        <fieldset class="form-group">
            <label>密码</label>
            <input type="password" class="form-control" name="password" id="password" placeholder="若不修改则无需填写" value="">
        </fieldset>
        <fieldset class="form-group hidden" id="surebox">
            <label>确认密码</label>
            <input type="password" class="form-control" name="password_confirm" placeholder="再次输入密码" value="">
        </fieldset>
        <fieldset class="form-group">
            <label>手机号码</label>
            <input type="number" class="form-control" name="mobile" placeholder="手机号码" value="{$info.mobile}">
        </fieldset>
        <fieldset class="form-group">
            <label>邮箱</label>
            <input type="email" class="form-control" name="email" placeholder="邮箱" value="{$info['email']}">
        </fieldset>
        <fieldset class="form-group">
            <label>头像</label>
            <input type="hidden" name="head_pic"  value="{$info['head_pic']}" >
            <div id="head_pic" class="configImage b-a-2 border-default">
                 <div class="dz-default dz-message text-light ">
                    <i class="fa fa-plus-square"></i>
                </div>
            </div>
        </fieldset>
        <div class="panel-footer text-right">
            <input type="submit" class="btn btn-primary" value="确认修改">
        </div>
    </form>
</div>
{/block}

{block name="javascript"}
<script>
    $(function () {
        $("#password").focus(function () {
            $("#surebox").removeClass('hidden');
        });
        var thisdom = $('#head_pic');
        var inputdom = thisdom.prev('input');
        var nowPicid = inputdom.val();
        var files = {};
        if ('' != inputdom.val()) {
            $.ajax({
                url: "{:url('filemanage/ajaxgetfileinfo')}",
                type: 'post',
                dataType: "json",
                async: false,
                data: {ids: nowPicid},
                success: function (data) {
                    if ('' != data) {
                        files = data;
                    }
                }
            });
        }
        thisdom.dropzone({
            url: "{:url('filemanage/upload',['dir'=>'images','module'=>'admin','watermark'=>0])}",
            dictRemoveFile: "删除图片",
            init: function () {
                //回调已上传图片
                if (!jQuery.isEmptyObject(files)) {
                    var mockFile = {
                        name: files.name,
                        size: files.size,
                        accepted: true,
                        status: 'success',
                        processing: false
                    };
                    this.options.addedfile.call(this, mockFile);
                    this.options.thumbnail.call(this, mockFile, '__UPLOAD__/' + files.path);
                    this.files[0] = mockFile;
                    delImgEvent(thisdom);
                }
            },
            resize: function (file) {
                return {
                    srcX: 0,
                    srcY: 0,
                    srcWidth: file.width,
                    srcHeight: file.height,
                    trgWidth: file.width,
                    trgHeight: file.height
                };
            },
            maxFiles: 1,
            maxfilesexceeded: function (file) {
                this.removeAllFiles();
                this.addFile(file);
            },
            success: function (file, response, e) {
                //移除当前图片  
//                thisdom.find('div.dz-preview:not(.dz-processing)').remove();
                if (response.status == 1) {
                    inputdom.attr('value', response.id);
                    delImgEvent(thisdom);
                    toastr['success'](response.info, '', {
                        closeButton: true
                    });
                } else {
                    var data = response.info;
                    if (!data) {
                        data = '未知错误：' + response;
                    }
                    toastr['error'](data, '', {
                        closeButton: true
                    });
                    //移除当前图片恢复之前图片
                        this.removeFile(file);
                         if (!jQuery.isEmptyObject(files)) {
                            var mockFile = {
                                  name: files.name,
                                  size: files.size,
                                  accepted: true,
                                  status: 'success',
                                  processing: false
                            };
                            this.options.addedfile.call(this, mockFile);
                            this.options.thumbnail.call(this, mockFile, '__UPLOAD__/'+files.path);
                            this.files[0] = mockFile;
                            delImgEvent(thisdom);
                        }
                }
            }
        });
        function delImgEvent(dom) {
            dom.find('.dz-remove').click(function () {
                bootbox.confirm({
                     message: '只从这里删除,但仍然保留在服务器中？',
                     className: 'bootbox-sm',
                     buttons: {
                           confirm: {
                                    label: '是的',
                                    className: 'btn-success'
                           },
                           cancel: {
                                    label: '从服务器删除',
                                    className: 'btn-default'
                           }
                     },
                    callback: function (result) {
                        if (!result) {
                            var id = inputdom.attr('value');
                            $.get("{:url('filemanage/delete')}", {id: id},
                                    function (data) {
                                        if (data === 'true') {
                                            toastr['success']('图片删除成功~', '', {
                                                closeButton: true
                                            });
                                        } else {
                                            toastr['error'](data, '', {
                                                closeButton: true
                                            });
                                        }
                                    },
                                    "text"
                                    );
                        }
                        inputdom.attr('value','');
                    }
                });
            });
        }
    });
</script>
{/block}